package org.dromara.xyyw.service.impl;

import org.dromara.common.core.utils.MapstructUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.dromara.xyyw.domain.XyywGoods;
import org.dromara.xyyw.domain.bo.XyywGoodsBo;
import org.dromara.xyyw.domain.query.XyywGoodsQuery;
import org.dromara.xyyw.domain.vo.XyywGoodsVo;
import org.dromara.xyyw.mapper.XyywGoodsMapper;
import org.dromara.xyyw.service.IXyywGoodsService;

import java.util.Collection;
import java.util.List;

/**
 * 商品Service业务层处理
 *
 * @author yf
 * @date 2024-05-29
 */
@Service
public class XyywGoodsServiceImpl extends ServiceImpl<XyywGoodsMapper, XyywGoods> implements IXyywGoodsService {

    /**
     * 查询商品
     *
     * @param goodId 主键
     * @return XyywGoodsVo
     */
    @Override
    public XyywGoodsVo queryById(Integer goodId) {
        return baseMapper.selectVoById(goodId);
    }

    /**
     * 查询商品列表
     *
     * @param query 查询对象
     * @return XyywGoodsVo
     */
    @Override
    public TableDataInfo<XyywGoodsVo> queryPageList(XyywGoodsQuery query) {
        return PageQuery.of(() -> baseMapper.queryList(query));
    }

    /**
     * 查询商品列表
     *
     * @param query 查询对象
     * @return XyywGoodsVo
     */
    @Override
    public List<XyywGoodsVo> queryList(XyywGoodsQuery query) {
        return baseMapper.queryList(query);
    }

    /**
     * 根据新增业务对象插入商品
     *
     * @param bo 商品新增业务对象
     * @return Boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean insertByBo(XyywGoodsBo bo) {
        XyywGoods add = MapstructUtils.convert(bo, XyywGoods.class);
        return save(add);
    }

    /**
     * 根据编辑业务对象修改商品
     *
     * @param bo 商品编辑业务对象
     * @return Boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateByBo(XyywGoodsBo bo) {
        XyywGoods update = MapstructUtils.convert(bo, XyywGoods.class);
        return updateById(update);
    }

    /**
     * 校验并批量删除商品信息
     *
     * @param ids 主键集合
     * @return Boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteWithValidByIds(Collection<Integer> ids) {
        return removeByIds(ids);
    }
}
